<template>
	<view class="page">
	
		<view v-if="type==1">
			<view class="datatime">
				<view class="time time1">
					<picker mode="date" :value="datetime1" :start="startDate" :end="endDate" @change="bindDateChange">
						<view class="uni-input">开始：{{date1}}</view>
					</picker>
				</view>
				<view>至</view>
				<view class="time time2">
					<picker mode="date" :value="datetime2" :start="startDate" :end="endDate" @change="bindDateChange2">
						<view class="uni-input">结束：{{date2}}</view>
					</picker>
				</view>
				<view class="sosobut" @click="soinfo">搜索</view>
			</view>
				<block v-if="list.length>0">
			<view class="village-item" v-for="i,index in list" :key="index">
				<view class="village-item-left">
					<view class="village-item-left-title">
						<view class="shuxian"></view>
						<view class="village-item-left-content">
							<text>
								设备编号：{{i.number}}
							</text>
							<text class="village-item-left-content-status">
								<template v-if="i.status=='0'&&i.usestatus =='0'">
									(未完成)
								</template>
								<template v-if="i.status=='1'&&i.usestatus =='0'">
									(待审核)
								</template>
								<template v-if="i.status=='1'&&i.usestatus =='1'">
									(已审核)
								</template>
								<template v-if="i.status=='1'&&i.usestatus =='2'">
									(审核未通过)
								</template>
							</text>
						</view>
					</view>
					<view class="village-item-left-title mt10">地址：{{i.equipment.address}}</view>
					<view class="village-item-left-time">
						<image class="village-item-left-time-icon" src="../../static/clock.png" mode="widthFix"></image>
						<view class="">
							{{i.create_time_text}}-{{i.close_time_text}}
						</view>
					</view>
				</view>
				<view class="" style="display: flex;">
					<view class="village-item-right" @tap="$navTo('./details?id='+i.id+'&status=' + i.status+'&alltype='+info.alltype)">
						检查
					</view>
					<view class="village-item-right" @tap="navMap(i.equipment)">
						导航
					</view>
				</view>
				
			</view>
			</block>
			<view v-else style="text-align: center;padding: 40rpx 0;">暂无内容</view>
		</view>
		<view v-if="type==2">
			<block v-if="list.length>0">
				<view class="village-item" v-for="i,index in list" :key="index" >
					<view class="village-item-left">
						<view class="village-item-left-title">
							<view class="shuxian"></view>
							<view class="village-item-left-content">
								<text>
									设备编号：{{i.number}}
								</text>
							 
							</view>
						</view>
						<view class="village-item-left-title mt10">分类：{{i.name}}</view>
						<view class="village-item-left-title mt10">地址：{{i.address}}</view>
						 
					</view>
					<view class="" style="display: flex;">
						<view class="village-item-right" @tap="$navTo('/pagesB/repair/recordList?id='+i.id+'&type='+info.allalltype)">
							历史记录
						</view>
						 
					</view>
					
				</view>
			</block>
			<view v-else style="text-align: center;padding: 40rpx 0;">暂无内容</view>
		</view>
		
	</view>
</template>

<script>
	function getDate(type) {
		const date = new Date();
	
		let year = date.getFullYear();
		let month = date.getMonth() + 1;
		let day = date.getDate();
	
		if (type === 'start') {
			year = year - 3;
		} else if (type === 'end') {
			year = year;
		}
		month = month > 9 ? month : '0' + month;;
		day = day > 9 ? day : '0' + day;
	
		return `${year}-${month}-${day}`;
	}
	export default {
		data() {
			return {
				datetime1: getDate({
					format: true
				}), 
				datetime2: getDate({
					format: true
				}),
				date2:'选择结束时间',
				date1:'选择开始时间',
				startDate:getDate('start'),
				endDate:getDate('end'),
				list:[],
				info:{},
				info2:{},
				type:1,
			}
		},
		onLoad(e) {
			console.log(e.listtype)
			this.type=e.listtype
			if(e.listtype==1){
				this.info.alltype = e.alltype
				this.info.allalltype= e.allalltype
				this.info.task_id = e.task_id
				this.init()
				
			}else if(e.listtype==2){
				this.info.alltype = e.alltype
				this.info.allalltype= e.allalltype
				this.info.village_id = e.task_id
				this.init2()
			}
			
			
		},
		onShow() {
			
		},
		methods: {
			bindDateChange: function(e) {
				this.datetime1 = e.detail.value
				this.date1 = e.detail.value
			},
			bindDateChange2: function(e) {
				this.datetime2 = e.detail.value
				this.date2 = e.detail.value
			},
			navMap(i){
				uni.openLocation({
					address:i.address,
					latitude:Number(i.lat),
					longitude:Number(i.long)
				})
			},
			soinfo(){
				//stime 开始时间  etime结束时间
					this.info.stime=this.date1
					this.info.etime=this.date2
					this.init()
			},
			init(){
				let _this = this; 
				_this.$request.request({
					url: 'staff/equipment_list',
					method: 'POST',
					header:{
						token: uni.getStorageSync('token')
					},
					data:_this.info,
				}).then(res => {
					console.log('_this.info',_this.info);
					console.log('token',uni.getStorageSync('token'));
					if (res.data.code == 1) {
						_this.list = res.data.data
					} else {
						uni.showToast({
							title: res.data.msg,
							icon: 'none'
						})
					}
				})
			},
			init2(){
				let _this = this; 
				_this.$request.request({
					url: 'staff/getvillageeqlist',
					method: 'POST',
					header:{
						token: uni.getStorageSync('token')
					},
					data:_this.info,
				}).then(res => {
					console.log('_this.info',_this.info);
					console.log('token',uni.getStorageSync('token'));
					if (res.data.code == 1) {
						_this.list = res.data.data
					} else {
						uni.showToast({
							title: res.data.msg,
							icon: 'none'
						})
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.page{
		min-height: 100vh;
		background: #F5F5F5;
		padding-top: 20rpx;
	}
	
	.mt10{
		margin-top: 10rpx;
	}
	.datatime{
		display: flex;
		justify-content: space-between;
		padding: 0 20rpx;
		height:80rpx;
		line-height: 80rpx;
		.time{
			width: 268rpx;
			background: #fff;
		}
		.sosobut{
			    border-radius: 10rpx;
			    padding: 0 24rpx;
			background: #FFFFFF;
		}
		.time1{
			padding-left: 10rpx;
		}
		.time2{
			    padding-right: 10rpx;
			    text-align: right;
		}
	}
	.village-item{
		display: flex;
		align-items: center;
		padding: 20rpx 32rpx;
		background: #FFFFFF;
		border-radius: 20rpx;
		margin-top: 20rpx;
		justify-content: space-between;
		.village-item-left{
			flex: 1;
			.village-item-left-title{
				display: flex;
				align-items: center;
				.shuxian{
					width: 6rpx;
					height: 30rpx;
					background: #003690;
					border-radius: 10rpx;
					margin-right: 20rpx;
				}
				.village-item-left-content{
					display: flex;
					align-items: center;
					font-size: 30rpx;
					.village-item-left-content-status{
						font-size: 26rpx;
						color: #003690;
					}
				}
			}
			.village-item-left-time{
				display: flex;
				align-items: center;
				color: #999999;
				font-size: 28rpx;
				margin-top: 18rpx;
				.village-item-left-time-icon{
					width: 20rpx;
					margin-right: 20rpx;
				}
			}
		}
		.village-item-right{
			padding: 6rpx 20rpx;
			border-radius: 20rpx;
			color: #003690;
			font-size: 28rpx;
			border: 1rpx solid #003690;
			margin-left: 10rpx;
		}
	}
</style>
